package com.miao.controller.front;

import com.miao.dao.ParttimeDao;
import com.miao.entity.Parttime;
import com.miao.service.ParttimeService;
import com.miao.vo.PageVo;
import com.miao.vo.ParttimeVo;
import com.miao.vo.ResultVo;
import com.miao.vo.UserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: 丰
 * @date: 2023/3/2 18:00
 */
@RestController
@RequestMapping("/front/parttime")
@Api(tags = "兼职信息接口")
public class ParttimeController {

    @Autowired
    private ParttimeService parttimeService;


    @GetMapping("/getAll")
    @ApiOperation("条件分页查询")
    public ResultVo<List<ParttimeVo>> getAll( PageVo pageVo){

        List<ParttimeVo> pageVos = parttimeService.conditionQuery(pageVo);


        return ResultVo.success(pageVos);

    }



    @GetMapping("/get/{parttimeId}")
    @ApiOperation("根据兼职id查询兼职信息")
    public ResultVo<List<ParttimeVo>> get(@PathVariable("parttimeId") Integer parttimeId){

        List<ParttimeVo> serviceId = parttimeService.getId(parttimeId);
        return ResultVo.success(serviceId);
    }



    @GetMapping("/getAllById/{userId}")
    @ApiOperation("雇主id查询兼职信息")
    public ResultVo<List<ParttimeVo>> getAllById(@PathVariable("userId") Integer userId){

        List<ParttimeVo> all = parttimeService.getAllById(userId);

        return ResultVo.success(all);
    }





    @PostMapping("/modify/{parttimeId}")
    @ApiOperation("根据兼职id编辑兼职信息")
    public ResultVo modify(@RequestBody ParttimeVo parttimeVo){

        ResultVo modify = parttimeService.modify(parttimeVo);

        return modify;


    }



    @GetMapping("/delete/{parttimeId}")
    @ApiOperation("根据兼职id删除兼职信息")
    public ResultVo<Integer> delete(@PathVariable("parttimeId") Integer parttimeId){

        ResultVo resultVo = parttimeService.idByDel(parttimeId);
        return resultVo;
    }




    //TODO 还需要添加订单，返回的是订单号

    @PostMapping("/add")
    @ApiOperation("添加兼职")
    public ResultVo<String> add(@RequestBody ParttimeVo parttimeVo){

        ResultVo resultVo = parttimeService.addParttime(parttimeVo);

        return resultVo;


    }


}
